<?php 
/**
 * @orm tablename wb_pages
 */
class WbPageBasic extends WbPage {
	
	/**
	 * @orm char(255)
	 */
	public $title;
	/**
	 * @orm longtext
	 */
	public $contents;
	/**
	 * @orm owns many WbPageBasicContentImage inverse page
	 */
	public $contentImages;
	/**
	 * @orm owns many WbPageBasicGalleryImage inverse page
	 */
	public $galleryImages;
	/**
	 * @orm int(11)
	 */
	public $galleryImagesPerPage = 9;
	/**
	 * @orm plugin DomArImage({autoRename=1r})
	 * @orm listener afterAdd afterAddImage
	 */
	public $image;
	/**
	 * @orm plugin DomArImage({autoRename=1r})
	 */
	public $icon;
	
	public function afterAddImage() {
		if( $this->image->exists() == false ) {
			return;
		}
		
		$config = Wb::getModuleConfig( 'WbPageBasic' );
		
		$this->image->resize( $config['image']['imageWidth'], $config['image']['imageHeight']);
		$this->icon = $this->image->copy();
		$this->icon->resize($config['image']['iconWidth'], $config['image']['iconHeight'],false);
		$this->icon->cut($config['image']['iconWidth'], $config['image']['iconHeight']);
	}
	
	public function getParsedContents() {
		return WbSiteDocument::replaceDocumentKeys( $this->contents );
	}

	public function getTreeIcon() {
		return 'file';
	}
}